<template>
  <div class="container">
    <div
      v-loading="showLoading"
      class="loading"
      element-loading-text="正在拼命初始化..."
      element-loading-background="rgba(0, 0, 0, 0.8)"
    >
      <div class="chat-wrapper">
        <el-row>
          <el-col :xs="8" :sm="5" :xl="4">
            <side-bar />
          </el-col>
          <el-col :xs="16" :sm="12" :xl="14">
            <current-conversation />
          </el-col>
          <el-col :xs="0" :sm="7" :xl="6">
            <coustomer :customerid="conversationTo" />
          </el-col>
        </el-row>
      </div>
      <call-layer ref="callLayer" class="chat-wrapper" />
      <image-previewer />
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import CurrentConversation from '@/components/TIM/conversation/current-conversation';
import SideBar from '@/components/TIM/layout/side-bar';
import ImagePreviewer from '@/components/TIM/message/image-previewer.vue';
import CallLayer from '@/components/TIM/message/call-layer';
import { getQueryVariable } from '@/utils';

import Coustomer from '@/components/TIM/customer';

export default {
  name: 'Chat',
  title: '佰材网-在线客服',
  components: {
    SideBar,
    CurrentConversation,
    ImagePreviewer,
    CallLayer,
    Coustomer
  },
  data() {
    return {
      conversationTo: ''
    };
  },
  computed: {
    ...mapState({
      isSDKReady: state => state.user.isSDKReady,
      userID: state => state.user.userID
    }),
    // 是否显示 Loading 状态
    showLoading() {
      return !this.isSDKReady;
    }
  },

  mounted() {
    // 初始化监听器
    this.conversationTo = getQueryVariable('to');
    this.conversationTo && this.addCoversation(this.conversationTo);
  },
  methods: {
    addCoversation(conversationTo) {
      if (conversationTo !== '@TIM#SYSTEM' && conversationTo) {
        this.$store
          .dispatch('checkoutConversation', `C2C${conversationTo}`)
          .then(() => {
          })
          .catch(() => {
            this.$store.commit('showMessage', {
              message: '没有找到该用户',
              type: 'warning'
            });
          });
      } else {
        this.$store.commit('showMessage', {
          message: '没有找到该用户',
          type: 'warning'
        });
      }
    }
  }
};
</script>

<style lang="stylus">
body {
  overflow: hidden;
  margin: 0;
  font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif
  // text-shadow: $regular 0 0 0.05em
  background-color: $bg;
  -ms-scroll-chaining: chained;
  -ms-overflow-style: none;
  -ms-content-zooming: zoom;
  -ms-scroll-rails: none;
  -ms-content-zoom-limit-min: 100%;
  -ms-content-zoom-limit-max: 500%;
  -ms-scroll-snap-type: proximity;
  -ms-scroll-snap-points-x: snapList(100%, 200%, 300%, 400%, 500%);
  -ms-overflow-style: none;
  overflow: auto;

  div {
    box-sizing: border-box;

    &::before, &::after {
      box-sizing: border-box;
    }
  }
}

#wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  padding-top: 100px;
}

.container
  position relative
  height calc(100vh - 195px)
// TODO filter mac chrome 会有问题，下次修改可以去掉
.bg {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: -1;
  background: #0A2140;
  background-size: cover;
  // filter blur(67px)
}

.loading {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
}

.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-wrapper {
  margin-top: 0;
  width: $width;
  height: $height;
  max-width: 1280px;
  box-shadow: 0 11px 20px 0 rgba(0, 0, 0, 0.3);

  .official-link {
    display: flex;
    text-decoration: none;
    color: #38c9ff;
    width: fit-content;
    float: right;
    height: 45px;
    align-items: center;
  }
}
/* 设置滚动条的样式 */
::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}

/* 滚动槽 */
::-webkit-scrollbar-track {
  border-radius: 10px;
}

/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.1);
}
</style>
